## build CMakeList of the executable file

cmake_minimum_required(VERSION 3.16)

#####add this before project
include(commCfg.cmake)

project(mycheck)

set (libModAdd add)

option(MOD_NOT_NEED_CFG "MOD_NOT_NEED_CFG" ON)

set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/install)
message(STATUS "install path: "${CMAKE_INSTALL_PREFIX})

file(GLOB SUBDIRS "*/")
foreach(SUBDIR ${SUBDIRS})
    string(REGEX REPLACE "/$" "" SUBDIR ${SUBDIR})
    if (EXISTS ${SUBDIR}/CMakeLists.txt)
        add_subdirectory(${SUBDIR})
    endif()
endforeach()

set(SOURCE_FILES
    main.cpp
        )

#设置执行文件名

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
    set(EXECUTABLE_NAME "demo_darwin_amd64")
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
    set(EXECUTABLE_NAME "tadd")
endif ()

# test cases添加执行文件，执行文件的入口文件，也就是包含main函数的文件
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
# link opencv libs,指定在链接目标文件的时候需要链接到外部库，其效果类似gcc的编译参数“-l”，可以解决外部库的依赖问题。
target_link_libraries(${EXECUTABLE_NAME} -ldl -lm -lpthread -lrt ${libModAdd})

install(TARGETS ${EXECUTABLE_NAME}
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    PUBLIC_HEADER DESTINATION include
)

install(FILES run.sh DESTINATION bin
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
    GROUP_READ GROUP_EXECUTE
    WORLD_READ WORLD_EXECUTE
)
